﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace 图书借阅系统
{
    public partial class 用户登录 : System.Web.UI.Page
    {
        string s = System.Configuration.ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(s);
            string userId = TextBox1.Text.Trim();
            string userPwd = TextBox2.Text.Trim();
            string selectStr =@"select 姓名
                                from 用户
                                where id="+userId+" and 密码="+userPwd+"";
            if (Connection.Count(selectStr,0)!=null)
            {
                Session["userID"] = userId;
                Session["userN"] = userPwd;
                Session["userName"] = Convert.ToString(Connection.Count(selectStr, 0));
                TextBox1.Text = "";
                TextBox2.Text = "";
                Response.Redirect("用户.aspx");
            }
            else
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('读者号或密码输入错误，请检查！');</script>"); 
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("读者注册.aspx");
        }
    }
}